import request from '@/utils/request'
import type { SpaceDTO, UpdateSpaceDTO } from '@/api/DTO/space'
import type { AxiosResponse } from 'axios'
const baseURL = '/space'
//1. 获取全部空间
export const getLoginUserSpacesServer = () => {
  return request.get(baseURL + '/all')
}
//2.获取根空间
export const getLoginUserRootSpacesServer = () => {
  return request.get(baseURL + '/root')
}

//2.5 获取空间信息
export const getSpaceServer = (spaceId: any) => {
  return request.get(baseURL, { params: { spaceId } })
}
//2.75 获取空间树
export const getSpaceTreeServer = (spaceId: any) => {
  return request.get(baseURL + '/info', { params: { spaceId } })
}
//3.更新空间
export const updateSpaceServer = (data: UpdateSpaceDTO) => {
  return request.put(baseURL, data)
}

//4. 新增一个空间 必须要有父空间id
export const addSpaceServer = (data: SpaceDTO): Promise<AxiosResponse<any>> => {
  return request.post(baseURL, data)
}

//5. 删除空间，前提是空间为空
export const deleteSpaceServer = (spaceId: any) => {
  return request.delete(baseURL + '/delete', { params: { spaceId: spaceId } })
}
